package yongxin.controller.kingdeeReport;

import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.tag.vo.datatable.SortDirection;
import org.jeecgframework.web.system.pojo.base.TSUser;
import org.jeecgframework.web.system.service.SystemService;

import yongxin.entity.annealer.AnnealerEntity;
import yongxin.entity.check.ContractEntity;
import yongxin.entity.check.ContractProcutEntity;
import yongxin.entity.processreport.ProcessReportEntity;
import yongxin.entity.temp_record.TempRecordEntity;
import yongxin.utils.ExcelUtils;

/**
 * @Title: Controller
 * @Description: 设备维修查询
 * @author zhangdaihao
 * @date 2015-02-05 14:03:13
 * @version V1.0
 * 
 */
@Controller
@RequestMapping("/equipmentController")
public class EquipmentController extends BaseController {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(EquipmentController.class);

	@Autowired
	private SystemService systemService;

	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * 
	 * 销售合同 列表
	 * 
	 * @return
	 */
	@RequestMapping(params = "equipment")
	public ModelAndView equipment(HttpServletRequest request) {

		return new ModelAndView("yongxin/kingdeeReport/equipmentList");

	}

	@RequestMapping(params = "equipment2")
	public ModelAndView equipment2(HttpServletRequest request) {

		return new ModelAndView("yongxin/kingdeeReport/equipmentList2");

	}

	@RequestMapping(params = "equipment3")
	public ModelAndView equipment3(HttpServletRequest request) {

		return new ModelAndView("yongxin/kingdeeReport/equipmentList3");

	}

	@RequestMapping(params = "equipment4")
	public ModelAndView equipment4(HttpServletRequest request) {

		return new ModelAndView("yongxin/kingdeeReport/equipmentList4");

	}

	/**
	 * easyui 设备维修计划表
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

		String FDeviceID37634_DSPName = request.getParameter("FDeviceID37634DSPName");   // 设备名称
		String FDeviceID39685_DSPName = request.getParameter("FDeviceID39685DSPName");   // 使用部门
		String FChargeEmp_DSPName = request.getParameter("FChargeEmpDSPName");  // 负责人
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ICDeviceRepairPlan.FEntrust,ICDeviceRepairPlan.FID,ICDeviceRepairPlan.FBillID,ICDeviceRepairPlan.FBillStatus, ";
		sql += "  vw_Device_Device1.FName AS FDeviceID37634DSPName,vw_Device_Device1.FNumber AS FDeviceIDFNDName,vw_Device_Device1_FDeviceID39685.FName AS FDeviceID39685DSPName, ";
		sql += "ICDeviceRepairPlan.FPlanBeginDate,ICDeviceRepairPlan.FPlanEndDate,ICDeviceRepairPlan.FLastRepairDate,ICDeviceRepairPlan.FNextRepairDate, ";
		sql += "ICDeviceRepairPlan.FRepairContent,ICDeviceRepairPlan.FNote,ICDeviceRepairPlan.FBillerID,t_User.FName AS FBillerID_FNDName, ";
		sql += "t_User.FName AS FBillerIDDSPName,ICDeviceRepairPlan.FBillDate,ICDeviceRepairPlan.FRepairID,ICDeviceRepairPlan.FCheckerID, ";
		sql += "t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName,ICDeviceRepairPlan.FCheckDate,isnull(ICDevInfo.FName,'') AS FRepairCatgDSPName, ";
		sql += "isnull(ICDeviceRepairPlanProject.FProjectName,'') FProjectName,isnull(t_Emp2.FName,'') AS FChargeEmpDSPName,isnull(ICDeviceRepairPlanProject.FNote,'') AS FNote_2  ";
		sql += "FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairPlan  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairPlanProject  ON ICDeviceRepairPlan.FID=ICDeviceRepairPlanProject.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device vw_Device_Device1 ON ICDeviceRepairPlan.FDeviceID=vw_Device_Device1.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device1_FDeviceID39685 ON vw_Device_Device1.FDeptNumber=vw_Device_Device1_FDeviceID39685.FItemID AND vw_Device_Device1_FDeviceID39685.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage3 ON ICDeviceRepairPlan.FPeriodUnit=t_SubMessage3.FInterID AND t_SubMessage3.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage1 ON ICDeviceRepairPlan.FTimeUnit=t_SubMessage1.FInterID AND t_SubMessage1.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairPlan.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairPlan.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.ICDevInfo  ON ICDeviceRepairPlan.FRepairCatg=ICDevInfo.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Supplier  ON ICDeviceRepairPlan.FRepairSubcntr=t_Supplier.FItemID AND t_Supplier.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Currency  ON ICDeviceRepairPlan.FCurrency=t_Currency.FCurrencyID AND t_Currency.FCurrencyID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage2 ON ICDeviceRepairPlanProject.FDesValueType=t_SubMessage2.FInterID AND t_SubMessage2.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp2 ON ICDeviceRepairPlanProject.FChargeEmp=t_Emp2.FItemID AND t_Emp2.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairPlanProject.FCheckEmp=t_Emp1.FItemID AND t_Emp1.FItemID<>0  where 1=1 ";
        
		if(StringUtil.isNotEmpty(FDeviceID37634_DSPName)){
			sql += " and vw_Device_Device1.FName like '%" + FDeviceID37634_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID39685_DSPName)){
			sql += " and vw_Device_Device1_FDeviceID39685.FName = '" + FDeviceID39685_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FChargeEmp_DSPName)){
			sql += " and t_Emp2.FName like '%" + FChargeEmp_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairPlan.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairPlan.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		List<Map<String, Object>> maplist = null;
		List<Map<String, Object>> allmaplist = null;

		try {

			allmaplist = systemService.findForJdbc(sql);
			maplist = systemService.findForJdbcParam(sql, dataGrid.getPage(), dataGrid.getRows());

		} catch (Exception ex) {

		}
		dataGrid.setTotal(allmaplist.size());
		dataGrid.setResults(maplist);
		TagUtil.datagrid(response, dataGrid);
	}
    
	
	/**
	 * 
	 * 導出
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	@RequestMapping(params = "export")
	public void export(HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid) {
	    

		String FDeviceID37634_DSPName = request.getParameter("FDeviceID37634DSPName");   // 设备名称
		String FDeviceID39685_DSPName = request.getParameter("FDeviceID39685DSPName");   // 使用部门
		String FChargeEmp_DSPName = request.getParameter("FChargeEmpDSPName");  // 负责人
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ICDeviceRepairPlan.FEntrust,ICDeviceRepairPlan.FID,ICDeviceRepairPlan.FBillID,ICDeviceRepairPlan.FBillStatus, ";
		sql += "  vw_Device_Device1.FName AS FDeviceID37634DSPName,vw_Device_Device1.FNumber AS FDeviceIDFNDName,vw_Device_Device1_FDeviceID39685.FName AS FDeviceID39685DSPName, ";
		sql += "Convert(varchar(50),ICDeviceRepairPlan.FPlanBeginDate,23) FPlanBeginDate,Convert(varchar(50),ICDeviceRepairPlan.FPlanEndDate,23) FPlanEndDate,ICDeviceRepairPlan.FLastRepairDate,ICDeviceRepairPlan.FNextRepairDate, ";
		sql += "ICDeviceRepairPlan.FRepairContent,ICDeviceRepairPlan.FNote,ICDeviceRepairPlan.FBillerID,t_User.FName AS FBillerID_FNDName, ";
		sql += "t_User.FName AS FBillerIDDSPName,Convert(varchar(50),ICDeviceRepairPlan.FBillDate,23) FBillDate,ICDeviceRepairPlan.FRepairID,ICDeviceRepairPlan.FCheckerID, ";
		sql += "t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName,Convert(varchar(50),ICDeviceRepairPlan.FCheckDate,23) FCheckDate,isnull(ICDevInfo.FName,'') AS FRepairCatgDSPName, ";
		sql += "isnull(ICDeviceRepairPlanProject.FProjectName,'') FProjectName,isnull(t_Emp2.FName,'') AS FChargeEmpDSPName,isnull(ICDeviceRepairPlanProject.FNote,'') AS FNote_2  ";
		sql += "FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairPlan  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairPlanProject  ON ICDeviceRepairPlan.FID=ICDeviceRepairPlanProject.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device vw_Device_Device1 ON ICDeviceRepairPlan.FDeviceID=vw_Device_Device1.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device1_FDeviceID39685 ON vw_Device_Device1.FDeptNumber=vw_Device_Device1_FDeviceID39685.FItemID AND vw_Device_Device1_FDeviceID39685.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage3 ON ICDeviceRepairPlan.FPeriodUnit=t_SubMessage3.FInterID AND t_SubMessage3.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage1 ON ICDeviceRepairPlan.FTimeUnit=t_SubMessage1.FInterID AND t_SubMessage1.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairPlan.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairPlan.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.ICDevInfo  ON ICDeviceRepairPlan.FRepairCatg=ICDevInfo.FID ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Supplier  ON ICDeviceRepairPlan.FRepairSubcntr=t_Supplier.FItemID AND t_Supplier.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Currency  ON ICDeviceRepairPlan.FCurrency=t_Currency.FCurrencyID AND t_Currency.FCurrencyID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage2 ON ICDeviceRepairPlanProject.FDesValueType=t_SubMessage2.FInterID AND t_SubMessage2.FInterID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp2 ON ICDeviceRepairPlanProject.FChargeEmp=t_Emp2.FItemID AND t_Emp2.FItemID<>0 ";
		sql += "LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairPlanProject.FCheckEmp=t_Emp1.FItemID AND t_Emp1.FItemID<>0  where 1=1 ";
        
		if(StringUtil.isNotEmpty(FDeviceID37634_DSPName)){
			sql += " and vw_Device_Device1.FName like '%" + FDeviceID37634_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID39685_DSPName)){
			sql += " and vw_Device_Device1_FDeviceID39685.FName = '" + FDeviceID39685_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FChargeEmp_DSPName)){
			sql += " and t_Emp2.FName like '%" + FChargeEmp_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairPlan.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairPlan.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		List<Map<String, Object>> maplist = null;

		try
		{
			maplist = systemService.findForJdbc(sql);
			List<String[]> list = new ArrayList<String[]>();
			
			for (Map<String, Object> map : maplist) {
				String[] arr = new String[map.size()];
				arr[0] = (String) map.get("FBillID");
				arr[1] = (String) map.get("FDeviceID37634DSPName");
				arr[2] = (String) map.get("FDeviceIDFNDName");
				arr[3] = (String) map.get("FDeviceID39685DSPName");
				arr[4] = (String) map.get("FProjectName");
				arr[5] = (String) map.get("FChargeEmpDSPName");
				arr[6] = (String) map.get("FPlanBeginDate");
				arr[7] = (String) map.get("FPlanEndDate");
				arr[8] = (String) map.get("FRepairCatgDSPName");
				arr[9] =  ((Integer)map.get("FEntrust") == 0) ?"否":"是";
				arr[10] =  (String) map.get("FBillerIDDSPName");
				arr[11] = (String) map.get("FBillDate");
				arr[12] = (String) map.get("FCheckerIDDSPName");
				arr[13] = (String) map.get("FCheckDate");
				arr[14] = (String) map.get("FNote_2");
				list.add(arr);
				 
			}
		
			String[] columnNames = new String[] { "单据编号", "设备名称", "设备代码", "使用部门","维修项目名称","负责人","计划开始日期","计划完工日期","维修类别","是否外包","制单人","制单日期","审核人","审核日期","项目备注"};
	       String titleName = "设备维修计划表.xls";

			OutputStream fOut = response.getOutputStream();
			response.setHeader("Content-Disposition", "attachment; filename="
					+ new String(titleName.getBytes("GB2312"), "ISO8859-1"));

	        ExcelUtils.create(request, list, columnNames, titleName, fOut);
			
		} catch (Exception ex)
		{

		}
		
	
	}
	
	
	
	
	
	/**
	 * 设备维修记录表
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	@RequestMapping(params = "datagrid2")
	public void datagrid2(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

		String FDeviceID37634_DSPName = request.getParameter("FDeviceID37634DSPName");   // 设备名称
		String FDeviceID39685_DSPName = request.getParameter("FDeviceID39685DSPName");   // 使用部门
		String FChargeEmp_DSPName = request.getParameter("FChargeEmpDSPName");  // 负责人
		
		String FProjectName = request.getParameter("FProjectName");  // 维修项目
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ";
		sql += " ICDeviceRepairRecord.FID,ICDeviceRepairRecord.FBillID,ICDeviceRepairRecord.FBillStatus,ICDeviceRepairRecord.FRepairWOBillID,ICDeviceRepairRecord.FDeviceID,vw_Device_Device1.FNumber AS FDeviceIDFNDName, ";
		sql += " vw_Device_Device1.FNumber AS FDeviceID_DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID37634,vw_Device_Device1.FName AS FDeviceID37634DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39654,vw_Device_Device1.FSpecification AS FDeviceID39654_DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39668, ";
		sql += " vw_Device_Device1.FModel AS FDeviceID39668DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39685,vw_Device_Device1_FDeviceID39685.FName AS FDeviceID39685DSPName,ICDeviceRepairRecord.FRepairNumber,ICDeviceRepairRecord.FRepairName,ICDeviceRepairRecord.FBeginDate, ";
		sql += " ICDeviceRepairRecord.FEndDate,ICDeviceRepairRecord.FRepairContent,ICDeviceRepairRecord.FRequire,ICDeviceRepairRecord.FTimeUnit,t_SubMessage1.FID AS FTimeUnit_FNDName,t_SubMessage1.FName AS FTimeUnit_DSPName, ";
		sql += " ICDeviceRepairRecord.FStopManHour,Convert(varchar(32),ICDeviceRepairRecord.FRepairManHour) FRepairManHour,ICDeviceRepairRecord.FNote,ICDeviceRepairRecord.FBillerID,t_User.FName AS FBillerID_FNDName,t_User.FName AS FBillerIDDSPName, ";
		sql += " ICDeviceRepairRecord.FBillDate,ICDeviceRepairRecord.FRepairWOID,ICDeviceRepairRecord.FRepairID,ICDeviceRepairRecord.FCheckerID,t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName, ";
		sql += " ICDeviceRepairRecord.FCheckDate,ICDeviceRepairRecord.FRepairCatg,ICDevInfo.FNumber AS FRepairCatg_FNDName,ICDevInfo.FName AS FRepairCatgDSPName,ICDeviceRepairRecord.FEntrust,ICDeviceRepairRecord.FRepairSubcntr, ";
		sql += " t_Supplier.FNumber AS FRepairSubcntr_FNDName,t_Supplier.FName AS FRepairSubcntr_DSPName,ICDeviceRepairRecord.FCurrency,t_Currency.FNumber AS FCurrency_FNDName,t_Currency.FScale AS FCurrency_Decimal,t_Currency.FName AS FCurrency_DSPName, ";
		sql += " ICDeviceRepairRecord.FPlanRepairFee,ICDeviceRepairRecord.FRepairFee,ICDeviceRepairRecord.FPlanStopManhour,ICDeviceRepairRecord.FPlanRepairManhour,ICDeviceRepairRecord.FClassTypeID,ICDeviceRepairRecordProject.FEntryID AS FEntryID2, ";
		sql += "  ICDeviceRepairRecordProject.FID AS FID2,ICDeviceRepairRecordProject.FIndex AS FIndex2,ICDeviceRepairRecordProject.FProjectName,ICDeviceRepairRecordProject.FWorkDescription,ICDeviceRepairRecordProject.FRepairRequire,ICDeviceRepairRecordProject.FDesValueType, ";
		sql += " t_SubMessage2.FID AS FDesValueType_FNDName,t_SubMessage2.FName AS FDesValueType_DSPName,ICDeviceRepairRecordProject.FDesValue,ICDeviceRepairRecordProject.FUpperDesValue,ICDeviceRepairRecordProject.FLowerDesValue,ICDeviceRepairRecordProject.FFactValue, ";
		sql += " ICDeviceRepairRecordProject.FChargeEmp,t_Emp2.FNumber AS FChargeEmp_FNDName,isnull(t_Emp2.FName,'') AS FChargeEmpDSPName,ICDeviceRepairRecordProject.FCheckEmp,isnull(t_Emp1.FNumber,'') AS FCheckEmp_FNDName,isnull(t_Emp1.FName,'') AS FCheckEmpDSPName, ";
		sql += " isnull(ICDeviceRepairRecordProject.FNote,'') AS FNote_2  FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairRecord  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairRecordProject  ON ICDeviceRepairRecord.FID=ICDeviceRepairRecordProject.FID ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device vw_Device_Device1 ON ICDeviceRepairRecord.FDeviceID=vw_Device_Device1.FID ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device1_FDeviceID39685 ON vw_Device_Device1.FDeptNumber=vw_Device_Device1_FDeviceID39685.FItemID AND vw_Device_Device1_FDeviceID39685.FItemID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage1 ON ICDeviceRepairRecord.FTimeUnit=t_SubMessage1.FInterID AND t_SubMessage1.FInterID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairRecord.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairRecord.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.ICDevInfo  ON ICDeviceRepairRecord.FRepairCatg=ICDevInfo.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Supplier  ON ICDeviceRepairRecord.FRepairSubcntr=t_Supplier.FItemID AND t_Supplier.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Currency  ON ICDeviceRepairRecord.FCurrency=t_Currency.FCurrencyID AND t_Currency.FCurrencyID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage2 ON ICDeviceRepairRecordProject.FDesValueType=t_SubMessage2.FInterID AND t_SubMessage2.FInterID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp2 ON ICDeviceRepairRecordProject.FChargeEmp=t_Emp2.FItemID AND t_Emp2.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairRecordProject.FCheckEmp=t_Emp1.FItemID AND t_Emp1.FItemID<>0  where 1=1 ";

		
		if(StringUtil.isNotEmpty(FDeviceID37634_DSPName)){
			sql += " and vw_Device_Device1.FName like '%" + FDeviceID37634_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID39685_DSPName)){
			sql += " and vw_Device_Device1_FDeviceID39685.FName = '" + FDeviceID39685_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FChargeEmp_DSPName)){
			sql += " and t_Emp2.FName like '%" + FChargeEmp_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FProjectName)){
			sql += " and ICDeviceRepairRecordProject.FProjectName like '%" + FProjectName + "%'";
		}
		
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairRecord.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairRecord.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		List<Map<String, Object>> maplist = null;
		List<Map<String, Object>> allmaplist = null;

		try {

			allmaplist = systemService.findForJdbc(sql);
			maplist = systemService.findForJdbcParam(sql, dataGrid.getPage(), dataGrid.getRows());

		} catch (Exception ex) {

		}
		dataGrid.setTotal(allmaplist.size());
		dataGrid.setResults(maplist);
		TagUtil.datagrid(response, dataGrid);
	}
    
	
	/**
	 * 
	 * 導出
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	@RequestMapping(params = "export2")
	public void export2(HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid) {
	    

		String FDeviceID37634_DSPName = request.getParameter("FDeviceID37634DSPName");   // 设备名称
		String FDeviceID39685_DSPName = request.getParameter("FDeviceID39685DSPName");   // 使用部门
		String FChargeEmp_DSPName = request.getParameter("FChargeEmpDSPName");  // 负责人
		
		String FProjectName = request.getParameter("FProjectName");  // 维修项目
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ";
		sql += " ICDeviceRepairRecord.FID,ICDeviceRepairRecord.FBillID,ICDeviceRepairRecord.FBillStatus,ICDeviceRepairRecord.FRepairWOBillID,ICDeviceRepairRecord.FDeviceID,vw_Device_Device1.FNumber AS FDeviceIDFNDName, ";
		sql += " vw_Device_Device1.FNumber AS FDeviceID_DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID37634,vw_Device_Device1.FName AS FDeviceID37634DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39654,vw_Device_Device1.FSpecification AS FDeviceID39654_DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39668, ";
		sql += " vw_Device_Device1.FModel AS FDeviceID39668DSPName,ICDeviceRepairRecord.FDeviceID AS FDeviceID39685,vw_Device_Device1_FDeviceID39685.FName AS FDeviceID39685DSPName,ICDeviceRepairRecord.FRepairNumber,ICDeviceRepairRecord.FRepairName,Convert(varchar(50),ICDeviceRepairRecord.FBeginDate,23)  FBeginDate,";
		sql += " Convert(varchar(50),ICDeviceRepairRecord.FEndDate,23) FEndDate,ICDeviceRepairRecord.FRepairContent,ICDeviceRepairRecord.FRequire,ICDeviceRepairRecord.FTimeUnit,t_SubMessage1.FID AS FTimeUnit_FNDName,t_SubMessage1.FName AS FTimeUnit_DSPName, ";
		sql += " ICDeviceRepairRecord.FStopManHour,Convert(varchar(32),ICDeviceRepairRecord.FRepairManHour) FRepairManHour,ICDeviceRepairRecord.FNote,ICDeviceRepairRecord.FBillerID,t_User.FName AS FBillerID_FNDName,t_User.FName AS FBillerIDDSPName, ";
		sql += " Convert(varchar(50),ICDeviceRepairRecord.FBillDate,23) FBillDate,ICDeviceRepairRecord.FRepairWOID,ICDeviceRepairRecord.FRepairID,ICDeviceRepairRecord.FCheckerID,t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName, ";
		sql += " Convert(varchar(50),ICDeviceRepairRecord.FCheckDate,23) FCheckDate,ICDeviceRepairRecord.FRepairCatg,ICDevInfo.FNumber AS FRepairCatg_FNDName,ICDevInfo.FName AS FRepairCatgDSPName,ICDeviceRepairRecord.FEntrust,ICDeviceRepairRecord.FRepairSubcntr, ";
		sql += " t_Supplier.FNumber AS FRepairSubcntr_FNDName,t_Supplier.FName AS FRepairSubcntr_DSPName,ICDeviceRepairRecord.FCurrency,t_Currency.FNumber AS FCurrency_FNDName,t_Currency.FScale AS FCurrency_Decimal,t_Currency.FName AS FCurrency_DSPName, ";
		sql += " ICDeviceRepairRecord.FPlanRepairFee,ICDeviceRepairRecord.FRepairFee,ICDeviceRepairRecord.FPlanStopManhour,ICDeviceRepairRecord.FPlanRepairManhour,ICDeviceRepairRecord.FClassTypeID,ICDeviceRepairRecordProject.FEntryID AS FEntryID2, ";
		sql += "  ICDeviceRepairRecordProject.FID AS FID2,ICDeviceRepairRecordProject.FIndex AS FIndex2,ICDeviceRepairRecordProject.FProjectName,ICDeviceRepairRecordProject.FWorkDescription,ICDeviceRepairRecordProject.FRepairRequire,ICDeviceRepairRecordProject.FDesValueType, ";
		sql += " t_SubMessage2.FID AS FDesValueType_FNDName,t_SubMessage2.FName AS FDesValueType_DSPName,ICDeviceRepairRecordProject.FDesValue,ICDeviceRepairRecordProject.FUpperDesValue,ICDeviceRepairRecordProject.FLowerDesValue,ICDeviceRepairRecordProject.FFactValue, ";
		sql += " ICDeviceRepairRecordProject.FChargeEmp,t_Emp2.FNumber AS FChargeEmp_FNDName,isnull(t_Emp2.FName,'') AS FChargeEmpDSPName,ICDeviceRepairRecordProject.FCheckEmp,isnull(t_Emp1.FNumber,'') AS FCheckEmp_FNDName,isnull(t_Emp1.FName,'') AS FCheckEmpDSPName, ";
		sql += " isnull(ICDeviceRepairRecordProject.FNote,'') AS FNote_2  FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairRecord  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairRecordProject  ON ICDeviceRepairRecord.FID=ICDeviceRepairRecordProject.FID ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device vw_Device_Device1 ON ICDeviceRepairRecord.FDeviceID=vw_Device_Device1.FID ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device1_FDeviceID39685 ON vw_Device_Device1.FDeptNumber=vw_Device_Device1_FDeviceID39685.FItemID AND vw_Device_Device1_FDeviceID39685.FItemID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage1 ON ICDeviceRepairRecord.FTimeUnit=t_SubMessage1.FInterID AND t_SubMessage1.FInterID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairRecord.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairRecord.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.ICDevInfo  ON ICDeviceRepairRecord.FRepairCatg=ICDevInfo.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Supplier  ON ICDeviceRepairRecord.FRepairSubcntr=t_Supplier.FItemID AND t_Supplier.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Currency  ON ICDeviceRepairRecord.FCurrency=t_Currency.FCurrencyID AND t_Currency.FCurrencyID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage t_SubMessage2 ON ICDeviceRepairRecordProject.FDesValueType=t_SubMessage2.FInterID AND t_SubMessage2.FInterID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp2 ON ICDeviceRepairRecordProject.FChargeEmp=t_Emp2.FItemID AND t_Emp2.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairRecordProject.FCheckEmp=t_Emp1.FItemID AND t_Emp1.FItemID<>0  where 1=1 ";

		
		if(StringUtil.isNotEmpty(FDeviceID37634_DSPName)){
			sql += " and vw_Device_Device1.FName like '%" + FDeviceID37634_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID39685_DSPName)){
			sql += " and vw_Device_Device1_FDeviceID39685.FName = '" + FDeviceID39685_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FChargeEmp_DSPName)){
			sql += " and t_Emp2.FName like '%" + FChargeEmp_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FProjectName)){
			sql += " and ICDeviceRepairRecordProject.FProjectName like '%" + FProjectName + "%'";
		}
		
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairRecord.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairRecord.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		List<Map<String, Object>> maplist = null;

		try
		{
			maplist = systemService.findForJdbc(sql);
			List<String[]> list = new ArrayList<String[]>();
			
			for (Map<String, Object> map : maplist) {
				String[] arr = new String[map.size()];
				arr[0] = (String) map.get("FBillID");
				arr[1] = (String) map.get("FDeviceID37634DSPName");
				arr[2] = (String) map.get("FDeviceIDFNDName");
				arr[3] = (String) map.get("FDeviceID39685DSPName");
				arr[4] = (String) map.get("FProjectName");
				arr[5] = (String) map.get("FFactValue");
				arr[6] = (String) map.get("FChargeEmpDSPName");
				arr[7] = (String) map.get("FCheckEmpDSPName");
				arr[8] =  (String)map.get("FBeginDate");
				arr[9] =  (String) map.get("FEndDate");
				arr[10] = (String) map.get("FRepairManHour");
				arr[11] = (String) map.get("FRepairCatgDSPName");
				arr[12] = ((Integer)map.get("FEntrust") == 0) ?"否":"是";
				arr[13] = (String) map.get("FBillerIDDSPName");
				arr[14] = (String) map.get("FBillDate");
				arr[15] = (String) map.get("FCheckerIDDSPName");
				arr[16] = (String) map.get("FCheckDate");
				arr[17] = (String) map.get("FNote_2");
				list.add(arr);
				 
			}
		
			String[] columnNames = new String[] { "单据编号", "设备名称", "设备代码", "使用部门","维修项目名称","实际值","负责人","检查人","实际开始日期","实际完工日期","实际维修工时","维修类别","是否外包","制单人","制单日期","审核人","审核日期","项目备注"};
	       String titleName = "设备维记录表.xls";

			OutputStream fOut = response.getOutputStream();
			response.setHeader("Content-Disposition", "attachment; filename="
					+ new String(titleName.getBytes("GB2312"), "ISO8859-1"));

	        ExcelUtils.create(request, list, columnNames, titleName, fOut);
			
		} catch (Exception ex)
		{

		}
		
	
	}
	
	
	/**
	 * 设备验收表
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	@RequestMapping(params = "datagrid3")
	public void datagrid3(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

		String FDeviceID51789_DSPName = request.getParameter("FDeviceID51789DSPName");   // 设备名称
		String FDeviceID32523_DSPName = request.getParameter("FDeviceID32523DSPName");   // 使用部门
		String FRepairCheckerID_DSPName = request.getParameter("FRepairCheckerIDDSPName");  // 负责人
		String FProjectName = request.getParameter("FProjectName");  // 维修项目
		
		String FRepairWOBillID = request.getParameter("FRepairWOBillID");  // 
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ";
		sql += " ICDeviceRepairCheck.FID,ICDeviceRepairCheck.FBillID,ICDeviceRepairCheck.FBillStatus,ICDeviceRepairCheck.FRepairWOBillID,ICDeviceRepairCheck.FDeviceID,vw_Device_Device.FNumber AS FDeviceIDFNDName, ";
		sql += " vw_Device_Device.FNumber AS FDeviceID_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID51789,vw_Device_Device.FName AS FDeviceID51789DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32478,vw_Device_Device.FSpecification AS FDeviceID32478_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32496, ";
		sql += " vw_Device_Device.FModel AS FDeviceID32496_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32523,vw_Device_Device_FDeviceID32523.FName AS FDeviceID32523DSPName,ICDeviceRepairCheck.FRepairCheckerID,t_Emp1.FNumber AS FRepairCheckerID_FNDName,t_Emp1.FName AS FRepairCheckerIDDSPName, ";
		sql += " ICDeviceRepairCheck.FRepairCheckResult,Convert(varchar(50),ICDeviceRepairCheck.FRepairCheckDate,23) FRepairCheckDate,ICDeviceRepairCheck.FNote,ICDeviceRepairCheck.FBillerID,t_User.FName AS FBillerID_FNDName,t_User.FName AS FBillerIDDSPName, ";
		sql += " ICDeviceRepairCheck.FBillDate FBillDate,ICDeviceRepairCheck.FRepairWOID,ICDeviceRepairCheck.FCheckerID,t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName,ICDeviceRepairCheck.FCheckDate, ";
		sql += "  ICDeviceRepairCheck.FClassTypeID,ICDeviceRepairCheckEntry.FEntryID AS FEntryID2,ICDeviceRepairCheckEntry.FID AS FID2,ICDeviceRepairCheckEntry.FIndex AS FIndex2,ICDeviceRepairCheckEntry.FProjectName,ICDeviceRepairCheckEntry.FCheckContent, ";
		sql += "  ICDeviceRepairCheckEntry.FDesValueType,t_SubMessage.FID AS FDesValueType_FNDName,t_SubMessage.FName AS FDesValueType_DSPName,ICDeviceRepairCheckEntry.FDesValue,ICDeviceRepairCheckEntry.FUpperDesValue,ICDeviceRepairCheckEntry.FLowerDesValue, ";
		sql += "  ICDeviceRepairCheckEntry.FFactValue,ICDeviceRepairCheckEntry.FNote AS FNote_2  FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairCheck  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairCheckEntry  ON ICDeviceRepairCheck.FID=ICDeviceRepairCheckEntry.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device  ON ICDeviceRepairCheck.FDeviceID=vw_Device_Device.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device_FDeviceID32523 ON vw_Device_Device.FDeptNumber=vw_Device_Device_FDeviceID32523.FItemID AND vw_Device_Device_FDeviceID32523.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairCheck.FRepairCheckerID=t_Emp1.FItemID AND t_Emp1.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairCheck.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairCheck.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage  ON ICDeviceRepairCheckEntry.FDesValueType=t_SubMessage.FInterID AND t_SubMessage.FInterID<>0 where 1=1 ";

		if(StringUtil.isNotEmpty(FDeviceID51789_DSPName)){
			sql += " and vw_Device_Device.FName like '%" + FDeviceID51789_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID32523_DSPName)){
			sql += " and vw_Device_Device_FDeviceID32523.FName = '" + FDeviceID32523_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FRepairCheckerID_DSPName)){
			sql += " and t_Emp1.FName = '" + FRepairCheckerID_DSPName + "'";
		}
		
		
		if(StringUtil.isNotEmpty(FProjectName)){
			sql += " and ICDeviceRepairCheckEntry.FProjectName like '%" + FProjectName + "%'";
		}
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairCheck.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairCheck.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		
		List<Map<String, Object>> maplist = null;
		List<Map<String, Object>> allmaplist = null;

		try {

			allmaplist = systemService.findForJdbc(sql);
			maplist = systemService.findForJdbcParam(sql, dataGrid.getPage(), dataGrid.getRows());

		} catch (Exception ex) {

		}
		dataGrid.setTotal(allmaplist.size());
		dataGrid.setResults(maplist);
		TagUtil.datagrid(response, dataGrid);
	}
     
	/**
	 * 
	 * 導出
	 * @param request
	 * @param response
	 * @param dataGrid
	 */
	@RequestMapping(params = "export3")
	public void export3(HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid) {
	    

		String FDeviceID51789_DSPName = request.getParameter("FDeviceID51789DSPName");   // 设备名称
		String FDeviceID32523_DSPName = request.getParameter("FDeviceID32523DSPName");   // 使用部门
		String FRepairCheckerID_DSPName = request.getParameter("FRepairCheckerIDDSPName");  // 负责人
		String FProjectName = request.getParameter("FProjectName");  // 维修项目
		
		String FRepairWOBillID = request.getParameter("FRepairWOBillID");  // 
		String FBillDate_begin = request.getParameter("FBillDate_begin");  // 制单日期
		String FBillDate_end = request.getParameter("FBillDate_end");    // 
		
		String sql = "	 SELECT  ";
		sql += " ICDeviceRepairCheck.FID,ICDeviceRepairCheck.FBillID,ICDeviceRepairCheck.FBillStatus,ICDeviceRepairCheck.FRepairWOBillID,ICDeviceRepairCheck.FDeviceID,vw_Device_Device.FNumber AS FDeviceIDFNDName, ";
		sql += " vw_Device_Device.FNumber AS FDeviceID_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID51789,vw_Device_Device.FName AS FDeviceID51789DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32478,vw_Device_Device.FSpecification AS FDeviceID32478_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32496, ";
		sql += " vw_Device_Device.FModel AS FDeviceID32496_DSPName,ICDeviceRepairCheck.FDeviceID AS FDeviceID32523,vw_Device_Device_FDeviceID32523.FName AS FDeviceID32523DSPName,ICDeviceRepairCheck.FRepairCheckerID,t_Emp1.FNumber AS FRepairCheckerID_FNDName,t_Emp1.FName AS FRepairCheckerIDDSPName, ";
		sql += " ICDeviceRepairCheck.FRepairCheckResult,Convert(varchar(50),ICDeviceRepairCheck.FRepairCheckDate,23) FRepairCheckDate,ICDeviceRepairCheck.FNote,ICDeviceRepairCheck.FBillerID,t_User.FName AS FBillerID_FNDName,t_User.FName AS FBillerIDDSPName, ";
		sql += " Convert(varchar(50),ICDeviceRepairCheck.FBillDate,23) FBillDate,ICDeviceRepairCheck.FRepairWOID,ICDeviceRepairCheck.FCheckerID,t_User1.FName AS FCheckerID_FNDName,t_User1.FName AS FCheckerIDDSPName,Convert(varchar(50),ICDeviceRepairCheck.FCheckDate,23) FCheckDate, ";
		sql += "  ICDeviceRepairCheck.FClassTypeID,ICDeviceRepairCheckEntry.FEntryID AS FEntryID2,ICDeviceRepairCheckEntry.FID AS FID2,ICDeviceRepairCheckEntry.FIndex AS FIndex2,ICDeviceRepairCheckEntry.FProjectName,ICDeviceRepairCheckEntry.FCheckContent, ";
		sql += "  ICDeviceRepairCheckEntry.FDesValueType,t_SubMessage.FID AS FDesValueType_FNDName,t_SubMessage.FName AS FDesValueType_DSPName,ICDeviceRepairCheckEntry.FDesValue,ICDeviceRepairCheckEntry.FUpperDesValue,ICDeviceRepairCheckEntry.FLowerDesValue, ";
		sql += "  ICDeviceRepairCheckEntry.FFactValue,ICDeviceRepairCheckEntry.FNote AS FNote_2  FROM  RemoteServer.AIS2009.dbo.ICDeviceRepairCheck  LEFT JOIN RemoteServer.AIS2009.dbo.ICDeviceRepairCheckEntry  ON ICDeviceRepairCheck.FID=ICDeviceRepairCheckEntry.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.vw_Device_Device  ON ICDeviceRepairCheck.FDeviceID=vw_Device_Device.FID ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Department vw_Device_Device_FDeviceID32523 ON vw_Device_Device.FDeptNumber=vw_Device_Device_FDeviceID32523.FItemID AND vw_Device_Device_FDeviceID32523.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_Emp t_Emp1 ON ICDeviceRepairCheck.FRepairCheckerID=t_Emp1.FItemID AND t_Emp1.FItemID<>0 ";
		sql += "  LEFT  JOIN RemoteServer.AIS2009.dbo.t_User  ON ICDeviceRepairCheck.FBillerID=t_User.FUserID AND t_User.FUserID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_User t_User1 ON ICDeviceRepairCheck.FCheckerID=t_User1.FUserID AND t_User1.FUserID<>0 ";
		sql += " LEFT  JOIN RemoteServer.AIS2009.dbo.t_SubMessage  ON ICDeviceRepairCheckEntry.FDesValueType=t_SubMessage.FInterID AND t_SubMessage.FInterID<>0 where 1=1 ";

		if(StringUtil.isNotEmpty(FDeviceID51789_DSPName)){
			sql += " and vw_Device_Device.FName like '%" + FDeviceID51789_DSPName + "%'";
		}
		if(StringUtil.isNotEmpty(FDeviceID32523_DSPName)){
			sql += " and vw_Device_Device_FDeviceID32523.FName = '" + FDeviceID32523_DSPName + "'";
		}
		if(StringUtil.isNotEmpty(FRepairCheckerID_DSPName)){
			sql += " and t_Emp1.FName = '" + FRepairCheckerID_DSPName + "'";
		}
		
		
		if(StringUtil.isNotEmpty(FProjectName)){
			sql += " and ICDeviceRepairCheckEntry.FProjectName like '%" + FProjectName + "%'";
		}
		if(StringUtil.isNotEmpty(FBillDate_begin)){
			sql += " and ICDeviceRepairCheck.FBillDate >= '" + FBillDate_begin + "'";
		}
		if(StringUtil.isNotEmpty(FBillDate_end)){
			sql += " and ICDeviceRepairCheck.FBillDate <= '" + FBillDate_end + "'";
		}
		
		if(dataGrid.getSort() != null)
		{
			String orderField = dataGrid.getSort();
			if(dataGrid.getSort().equals(orderField)){
				sql += " order by " + orderField + dataGrid.getOrder();
			}
		}
		
		
		List<Map<String, Object>> maplist = null;

		try
		{
			maplist = systemService.findForJdbc(sql);
			List<String[]> list = new ArrayList<String[]>();
			
			for (Map<String, Object> map : maplist) {
				String[] arr = new String[map.size()];
				arr[0] = (String) map.get("FBillID");
				arr[1] = (String) map.get("FDeviceID51789DSPName");
				arr[2] = (String) map.get("FDeviceIDFNDName");
				arr[3] = (String) map.get("FDeviceID39685DSPName");
				arr[4] = (String) map.get("FProjectName");
				arr[5] = (String) map.get("FFactValue");
				arr[6] = (String) map.get("FRepairCheckerIDDSPName");
				arr[7] = (String) map.get("FRepairCheckDate");
				arr[8] =  ((Integer)map.get("FRepairCheckResult") == 1) ?"正常":"";
				arr[9] =  (String) map.get("FRepairWOBillID");
				arr[10] = (String) map.get("FBillerIDDSPName");
				arr[11] = (String) map.get("FBillDate");
				arr[12] = (String) map.get("FCheckerIDDSPName");
				arr[13] = (String) map.get("FCheckDate");
				arr[14] = (String) map.get("FNote_2");
				list.add(arr);
				 
			}
		
			String[] columnNames = new String[] { "单据编号", "设备名称", "设备代码", "使用部门","维修项目名称","实际值","验收人","验收日期","验收结论","维修工单号","制单人","制单日期","审核人","审核日期","项目备注"};
	       String titleName = "设备验收表.xls";

			OutputStream fOut = response.getOutputStream();
			response.setHeader("Content-Disposition", "attachment; filename="
					+ new String(titleName.getBytes("GB2312"), "ISO8859-1"));

	        ExcelUtils.create(request, list, columnNames, titleName, fOut);
			
		} catch (Exception ex)
		{

		}
		
	
	}
	
}
